<?php
$isReloadable = true;
$isPopUp = true;
require_once("../../pers/inc.config.php");
require_once(OVF_FS_WEB_ROOT.'/app/_inc/inc.session.php');
require_once(OVF_FS_WEB_ROOT.'/app/_inc/funct.html.php');

if (reqVar('azione')=='conferma') {
	$sListIdAge = "";
	foreach($_REQUEST as $nX => $vX) {
		if (substr($nX,0,7)!='cb_idut') continue;
		$sListIdAge .= substr($nX,7).",";
	}
	if ($sListIdAge == "") {
		$msgPag .= _t("seleziona almeno un'agenda");
	} else {
		$sListIdAge = substr($sListIdAge,0,-1);
		$sSql = "SELECT u.nome, u.cognome FROM ovf_utenti u "
			." WHERE u.id_utente IN (".(($sListIdAge)?$sListIdAge:'0').") ";
		//dbg_($sSql);
		$objDB->query($sSql,'selUte');	
		$aNomiAge = array();
		while($acX = $objDB->fetch('selUte')) {
			$aNomiAge[] = $acX['nome']." ".$acX['cognome'];
		}
		$sListNomiAge = implode(", ",$aNomiAge);
		echo "chiusura in corso ...";	
		echo "<script>\n";
		echo "window.opener.document.frm1.listIdAge.value='$sListIdAge';\n";
		echo "oDiv = window.opener.document.getElementById('listNomiAge');\n";
		echo "if (oDiv) oDiv.innerHTML = \"".$sListNomiAge."\";\n";
		echo "window.close();\n";
		echo "</script>\n";
		exit();
	}
}
if (reqVar('listIdAge')!='') {
	$aX = explode(',',reqVar('listIdAge'));
	foreach($aX as $idX) {
		reqDef('cb_idut'.$idX,'S');
	}
}
$sSql = "SELECT * FROM ovf_utenti ORDER BY cognome,nome";
$objDB->query($sSql,'selUte');

$sCmdL  = "";

$sCmdR  = "&nbsp;&nbsp;&nbsp";
$sCmdR .=  "<a class='cmd1' href=\"javascript:document.frm1.azione.value='conferma';document.frm1.submit();\">"._t("conferma")."</a>";
$sCmdR .= "&nbsp;&nbsp;&nbsp";
$sCmdR .=  "<a class='cmd1' href='javascript:window.close();'>"._t("chiudi")."</a>";
$aOpt = array("width"=>600);
echo getTestaPopUpHtml("Selezione agende",$msgPag, $aOpt);
?>
<script type="text/javascript">
function confAgg() {
	if (confirm("<?=_t("Confermi l'aggiornamento della struttura del data-base ?")?>")) {
		document.frm1.azione.value='aggiorna';
		document.frm1.submit();
	}
}
</script>
<?
echo getHtmlForm();
echo getHtmlHidden('xsn');
echo getHtmlHidden('azione','...');
?>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='bottom'>
         <? echo $sCmdL;?>
      </td>
      <td class="cmd1" align="right" valign='bottom'>
         <? echo $sCmdR;?>
      </td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<tr>
		<td class="lab1" width='1%'>&nbsp;</td>
		<td class="lab1" width='99%'><?=_t("Agenda")?></td>
	</tr>
<?php 
$sTxtX = 'txt1';
while($acUte = $objDB->fetch('selUte')) {
	$sTxtX = ($sTxtX=='txt1')?'txt2':'txt1';
?>
	<tr>
		<td class="<?php echo $sTxtX?>" >
			<? echo getHtmlCheckBox('cb_idut'.$acUte['id_utente'], 'S');?>
		</td>
		<td class="<?php echo $sTxtX?>" >
			<? echo $acUte['cognome']." ".$acUte['nome'];?>
		</td>
	</tr>
<?php 
}
?>
</table>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='bottom'>
         <? echo $sCmdL;?>
      </td>
      <td class="cmd1" align="right" valign='bottom'>
         <? echo $sCmdR;?>
      </td>
   </tr>
</table>
<?php 
//print_r($aArt);
echo "</form>\n";
echo getCodaPopUpHtml();